import React from 'react';
import { Select } from 'antd';
import { valFormat } from '@/utils/utils';

/**
 * 选择预设选项
 * @param {array} options 选项
 * @param {string} labelName label字段
 */

export interface SelectProps {
  options: any;
  labelName: 'name';
  ref: any;
}
const SelectValues: React.FC<SelectProps> = (props) => {
  const { options, labelName, ref } = props;
  if (typeof options === 'string') {
    // options = valFormat[options] || [];
  } else if (typeof options !== 'object') {
    return null;
  }
  return (
    <Select ref={ref} allowClear>
      {Array.isArray(options)
        ? options.map((item) => (
            <Select.Option value={item.key} key={item.key}>
              {item[labelName]}
            </Select.Option>
          ))
        : Object.keys(options).map((key) => (
            <Select.Option value={key} key={key}>
              {options[key][labelName]}
            </Select.Option>
          ))}
    </Select>
  );
};
export default SelectValues;
